const mongoose = require('mongoose');

const connection = 'mongodb+srv://2818975440:19931573138%2E%40asd@cluster0.bjslyrs.mongodb.net';

mongoose.connect(connection, {
    useUnifiedTopology: true,
    useNewUrlParser: true,
})
    .then(() => {
        console.log('MongoDB 连接成功！');
    })
    .catch((err) => {
        console.error('MongoDB 连接失败:', err);
    });

const registerSchema = new mongoose.Schema({
    username: String,
    password: String,
    phone: String,
    resetPasswordCode:String
    
})
mongoose.connection.on('error', console.error);

const Food = new mongoose.Schema({
    name: String,
    price: Number,
    num: {
        type: Number,
        default: 0
    },
    cid: {
        type: mongoose.Types.ObjectId,
        ref: "Food"
    },
    img: String
})

const FoodCate = new mongoose.Schema({
    name: String,
})
const RoomDing=new mongoose.Schema({
    name:String,
    roomCate:String,
    startTime:Date,
    endTime:Date,
    status:String
})
//酒店信息，以及详情
const Hotel = new mongoose.Schema({
    city: String,
    img: String,
    title: String,
    oldPrice: Number,
    newPirce: Number,
    type: String,
    sort: String,
    sales: Number,
    evaluate: String,
    advantage: {
        type: Array,
        default: []
    },
    evaluateNum: Number,
    addr: String,
    year: Number,
    default: {
        type: Array,
        default: []
    },
    Ai: String,
    walk: Number,
    distance: Number,
    address: String,
})

const vipPrice = new mongoose.Schema({
    price:Number,
    num:Number,
    cid:mongoose.Types.ObjectId
})

const roomSchema = new mongoose.Schema({
    name: String,  // 酒店名称
    area: Number,  // 酒店面积
    people: Number,  // 酒店人数
    price: Number,    // 酒店价格
    // img:Array
    desc: String,      // 酒店描述
})
const orderSchema = new mongoose.Schema({
    start:Date, // 入住时间
    end:Date,   // 离店时间
    name:String, // 姓名
    phone:String, // 手机号
    day:Number,   // 可续住天数
    status:String, // 订单状态
    price:Number,  // 价格
    hname:String,  // 酒店名称
    room:String,    // 房间类型
    pay:String,    // 支付方式
    
})

const roomModel = mongoose.model('room', roomSchema, 'room')
const HotelModel = mongoose.model('Hotel', Hotel)
const orderModel = mongoose.model('order', orderSchema, 'order')
const vipPriceModel = mongoose.model("vipPrice",vipPrice)
const FoodModel = mongoose.model('Food', Food)
const FoodCateModel = mongoose.model('FoodCate', FoodCate)
const registerModel = mongoose.model("register", registerSchema, "register")
const roomDingModel = mongoose.model("RoomDing", RoomDing, "RoomDing")

mongoose.connection.on('error', console.error);

module.exports = {
    FoodModel,
    FoodCateModel,
    registerModel,
    roomDingModel,
    HotelModel,
    roomModel,
    orderModel,
    vipPriceModel,
}
